﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;


namespace An_Im.Theme.Custom
{
    /// <summary>
    /// AnWindow.xaml 的交互逻辑
    /// </summary>
    public partial class AnWindow : Window
    {

        public event EventHandler WindowClose;

        public AnWindow()
        {
            InitializeComponent();
        }

        protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
        {
            DragMove();
            base.OnMouseLeftButtonDown(e);
        }

        /// <summary>
        /// 标题栏的内容属性。
        /// </summary>
        public ControlTemplate TitleContent
        {
            get { return (ControlTemplate)GetValue(TitleContentProperty); }
            set { SetValue(TitleContentProperty, value); }
        }

        // 标题栏的内容属性。
        public static readonly DependencyProperty TitleContentProperty =
            DependencyProperty.Register("TitleContent", typeof(ControlTemplate), typeof(Window), null);


        /// <summary>
        /// 位于小按钮区域的模板内容。
        /// </summary>
        public ControlTemplate MiniContent
        {
            get { return (ControlTemplate)GetValue(MiniContentProperty); }
            set { SetValue(MiniContentProperty, value); }
        }

        // 小按钮的内容。
        public static readonly DependencyProperty MiniContentProperty =
            DependencyProperty.Register("MiniContent", typeof(ControlTemplate), typeof(Window), null);



        /// <summary>
        /// 是否允许通过双击修改窗体的最大化/正常状态。
        /// </summary>
        public bool AllowDoubleClickResizeWindow
        {
            get { return (bool)GetValue(AllowDoubleClickResizeWindowProperty); }
            set { SetValue(AllowDoubleClickResizeWindowProperty, value); }
        }

        /// <summary>
        /// 是否允许通过双击修改窗体的最大化/正常状态的依赖属性。
        /// </summary>
        public static readonly DependencyProperty AllowDoubleClickResizeWindowProperty =
            DependencyProperty.Register("AllowDoubleClickResizeWindow", typeof(bool), typeof(Window), new PropertyMetadata(true));



        public void SetUserControlContent(UserControl userControl)
        {
            this.Content = userControl;
        }

        public static AnWindow CreateWindow()
        {
            return CreateWindow(null);
        }

        public static AnWindow CreateWindow(UserControl userControl)
        {
            var window = new AnWindow();
            if (userControl != null)
            {
                window.Content = userControl;
            }
            return window;
        }

        public void ShowInWinForms()
        {
            this.Show();
        }

        public virtual void OnWindowClose()
        {
            WindowClose?.Invoke(this, EventArgs.Empty);
        }

        private void Close_Click(object sender, RoutedEventArgs e)
        {
            OnWindowClose();
            Hide();
        }

        private void MaxNormal_Click(object sender, RoutedEventArgs e)
        {
            if (this.WindowState == WindowState.Maximized)
                this.WindowState = WindowState.Normal;
            else if(this.WindowState == WindowState.Normal)
                this.WindowState = WindowState.Maximized;
        }
    }
}
